<?php

/**
 * +------------------------------------------------------------+
 * @category IndexAction
 * +------------------------------------------------------------+
 * 使用及关注药物
 * +------------------------------------------------------------+
 *
 * @author funwee@qq.com
 * @copyright http://www.suncco.com 2013
 * @version 1.0
 *
 * Modified at : 2013-10-22 上午10:51:44
 *
 */
class IndexAction extends Action {

    function index() {
        $categoryList = D('GroupCategory')->select();
        $this->assign('categoryList', $categoryList);
        $this->display();
    }

    function add() {
        $categoryid = isset($_GET['categoryid']) ? intval($_GET['categoryid']) : 0;
        if (!empty($_POST)) {
            $user = D('User')->find($this->mid);
            $arr = array();
            $arr['categoryid'] = intval($_POST['categoryid']);
            $arr['user_id'] = $user['id'];
            $arr['city_id'] = getAreaId($_POST['areaval']);
            $arr['hospital_id'] = getHospitalId($_POST['hospital']);
            $arr['departments_id'] = getKeshiId($_POST['keshi']);
            $arr['doctor_id'] = getDoctorId($_POST['doctor'], $arr['hospital_id'], $arr['departments_id']);
            $arr['add_time'] = time();
            D('UserDoctor')->add($arr);


            $discuz['doctor_id'] = $arr['doctor_id'];
            $discuz['user_id'] = $user['id'];
            $discuz['score'] = intval($_POST['fenshu']);
            $discuz['addtime'] = time();
            $discuz['cons'] = trim(htmlspecialchars($_POST['con']));
            D('DiscuzDoctor')->add($discuz);
            echo 1;
            exit();
        }
        $this->assign('categoryid', $categoryid);
        $this->display();
    }
    /**
     * 显示医生
     */
    public function showdoctor() {
        $categoryid = isset($_GET['id']) ? intval($_GET['id']) : 0;
        $user = D('User')->find($this->mid);
        $data=D('UserDoctor')->getUserDoctor($user['id'],$categoryid);
        if(!is_array($data)||empty($data)){
            echo 0;
        }
        print_r($data['data']);
        $this->assign('docbase', $data['data']);
         $this->assign('docscore', $data['score']);
        $this->display();
    }
    public function sortdoctor(){
        $city= isset($_GET['city']) ? getAreaId($_GET['city']):0;
        $categoryid = isset($_GET['id']) ? intval($_GET['id']) : 0;
        $scoremin=  isset($_GET['scoremin'])?intval($_GET['scoremin']):0;
        $scoremax=  isset($_GET['scoremax'])?intval($_GET['scoremax']):6;
        $data=D('UserDoctor')->sortDoctor($categoryid, $scoremin, $scoremax, $city = 0);
        print_r($data);
    }
}

?>